//初始化
function init() {
    var output = document.createElement('div');
    output.style.cssText = 'font-size: 100px;';
    document.body.appendChild(output);

    var tween = new TWEEN.Tween({x: 50, y: 0})
                .to({
                    x: 400
                }, 2000)
                .easing( TWEEN.Easing.Elastic.InOut)
                .onUpdate(function(obj) {
                    output.innerHTML = 'x==' + (Math.round(obj.x));
                    var transform = `translateX(${obj.x}px)`;
                    output.style.webkitTransform = transform;
                    output.style.transform = transform;
                })
                .start();
}

//动画函数
function animate(time) {
    requestAnimationFrame(animate);

    TWEEN.update();
}

init();
animate();